package com.you.atlas.web.place.module.control;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.TurbineRunData;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.CommentService;
import com.you.atlas.biz.place.service.NoteQueryService;
import com.you.atlas.biz.place.service.PlaceQueryService;
import com.you.common.ibatis.data.DataList;
import com.you.place.dal.dao.dataobject.NoteDO;
import com.you.place.dal.dao.dataobject.NoteItemDO;
import com.you.place.dal.dao.dataobject.PlaceDO;

public class NoteView {

    @Autowired
    private NoteQueryService  noteQueryService;

    @Autowired
    private PlaceQueryService placeQueryService;

    @Autowired
    private CommentService    commentService;

    public void execute(TurbineRunData rundata,@Param("pageNo") int pageNo, @Param("id") Long id, Context context, Navigator navigator) {
        NoteDO noteDO = noteQueryService.find(id);
        if (noteDO == null) {
            navigator.redirectTo("homeModule").withTarget("error.vm");
            rundata.getRedirectLocation();
            return;
        }
        PlaceDO placeDO = placeQueryService.find(noteDO.getPlaceId());
        List<NoteItemDO> noteItemList = noteQueryService.queryNoteItemByNoteId(id);
        DataList commentList = commentService.queryByFKId(pageNo, "note", id);

        context.put("noteDO", noteDO);
        context.put("placeDO", placeDO);
        context.put("noteItemList", noteItemList);
        context.put("commentList", commentList);
    }
}
